package com.qdlc.p2p.biz.model;

import java.util.HashMap;
import java.util.Map;

import com.qdlc.p2p.biz.service.UserService;
import com.qdlc.p2p.common.util.BeanUtil;
import com.qdlc.p2p.common.util.PropertiesUtil;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.dto.UserIdentify;
import com.qdlc.p2p.dal.model.UserModel;

public class AppAuthenticationModel extends UserModel {

    private Map<String, Object> data;

    /**
     * 生成 添加邮箱认证 响应信息
     *
     * @return
     */
    public Map<String, Object> emailResponse(User user, UserIdentify userIdentify, String email) {
        data = new HashMap<String, Object>();
        if (!StringUtil.isBlank(user)) {
            UserService userService = (UserService) BeanUtil.getBean("userService");
            int count = userService.countByEmail(email);
            if (count > 1) {
                data.put("resCode", "0");
                data.put("resMsg", PropertiesUtil.getValue("AppAuthentication04"));
                return data;
            } else {
//                userService.modifyEmail(getUserId(), email,getEmail(), 1);
                data.put("resCode", "1");
                data.put("resMsg", PropertiesUtil.getValue("AppAuthentication05"));
                return data;
            }
        } else {
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication06"));
            return data;
        }

    }

    public Map<String, Object> validParam() {
        if (StringUtil.isBlank(getRealName())) {
            data = new HashMap<String, Object>();
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication01"));
            return data;
        }

        if (StringUtil.isBlank(getCardId())) {
            data = new HashMap<String, Object>();
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication02"));
            return data;
        }

        if (StringUtil.isBlank(getUserId())) {
            data = new HashMap<String, Object>();
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication03"));
            return data;
        }
        return null;
    }

    /**
     * 检查邮箱认证 参数有效性
     *
     * @return
     */
    public Map<String, Object> validEmail() {
        data = new HashMap<String, Object>();
        if (StringUtil.isBlank(getUserId()) || getUserId() < 1) {
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication03"));
            return data;
        }
        if (StringUtil.isBlank(getEmail())) {
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication07"));
            return data;
        }
        return null;
    }

    public Map<String, Object> validPhone() {
        data = new HashMap<String, Object>();
        if (StringUtil.isBlank(getUserId()) || getUserId() < 1) {
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication03"));
            return data;
        }
        if (StringUtil.isBlank(getMobilePhone())) {
            data.put("resCode", "0");
            data.put("resMsg", PropertiesUtil.getValue("AppAuthentication07"));
            return data;
        }
        return null;
    }
}
